﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AnalisisDeRiesgosConfiguration.Model;
using MySql.Data.MySqlClient;
using AnalisisDeRiesgosConfiguration.Exceptions;

namespace AnalisisDeRiesgosConfiguration.DataAccess
{
    class ManagementDataAccess
    {
        DatabaseConnectionString connectionString;

        public ManagementDataAccess(DatabaseConnectionString theConnectionString)
        {
            connectionString = theConnectionString;
        }

        public void CreateManagement(Management theManagement)
        {
            try
            {
                using (MySqlConnection connection = new MySqlConnection(connectionString.ConnectionStringDB))
                {
                    connection.Open();
                    string sql = "INSERT INTO management " +
                                "(name, responsible)" +
                                "VALUES" +
                                "(@name, @responsible)";
                    MySqlCommand command = new MySqlCommand(sql, connection);

                    command.Parameters.AddWithValue("@name", theManagement.Name);
                    command.Parameters.AddWithValue("@responsible", theManagement.CI);
                    command.ExecuteNonQuery();
                    connection.Close();
                }

            }
            catch (Exception ex)
            {
                throw new DataAccessException(ex.Message);
            }
        }
    }
}
